Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

423
Views
"DELETE FROM locations ORDER BY id DESC LIMIT" 1 on knex.js not working

I try write this command:

DELETE FROM locations ORDER BY id DESC LIMIT 1

on knex.js. I write this code:

knex('locations').delete().orderBy('id', 'desc').limit(1).toString()

But it return

DELETE FROM locations

Why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Because LIMIT is not supported by Postgres and Knex is supposed to be compatible with both MySQL and PostgreSQL. See GitHub issue:

[...] this syntax isn't supported in Postgres, so that might be a bit unexpected if it's possible in one database and not another [...]

Please open a new feature request if you need this functionality to be changed.

It was mentioned there that it works since 0.6 but I can't verify that, it seems still to be not working, and that seems to be a design choice. (Personally I find this quite problematic because there is no error, you just silently get everything deleted.)

The only way to handle a DELETE LIMIT statement would be as raw query with knex.raw then.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!